//
//  OMGHomeTableViewCell.m
//  A_project2.0
//
//  Created by Tiny on 16/3/10.
//  Copyright © 2016年 七平. All rights reserved.
//

#import "OMGHomeTableViewCell.h"
#import "OMGHomeModel.h"


@implementation OMGHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 图片
        self.photo = [[UIImageView alloc]init];
        //        _photo.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_photo];
        
        // 标题
        self.title = [[UILabel alloc]init];
        //        self.title.backgroundColor = [UIColor cyanColor];
        _title.numberOfLines = 0;
        _title.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_title];
        
        // 用户名
        self.username = [[UILabel alloc]init];
        //        self.username.backgroundColor = [UIColor yellowColor];
        _username.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_username];

        
        // 查看人数
        self.views = [[UILabel alloc]init];
        //        self.views.backgroundColor = [UIColor blueColor];
        _views.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_views];

        
        // 回复
        self.replys = [[UILabel alloc]init];
        //        self.replys.backgroundColor = [UIColor magentaColor];
        _replys.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_replys];

        
        // 回复 image
        self.replysimg = [[UIImageView alloc]init];
        self.replysimg.image = [UIImage imageNamed:@"iconfont-chakan-2"];
        [self.contentView addSubview:_replysimg];

        
        // 查看 image
        self.viewimg = [[UIImageView alloc]init];
        self.viewimg.image = [UIImage imageNamed:@"iconfont-pinglun"];
        [self.contentView addSubview:_viewimg];


    }
    return self;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    WS(ws);
    // 图片
    [super layoutSubviews];
    [_photo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.mas_left).with.offset(10);
        make.top.equalTo(ws.mas_top).with.offset(10);
        make.width.equalTo(@100);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
    }];
    // 标题
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_photo.mas_right).with.offset(10);
        make.right.equalTo(ws.mas_right).with.offset(-10);
        make.top.equalTo(ws.mas_top).with.offset(10);
        make.height.equalTo(@40);
    }];
    // 用户名
    [_username mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_photo.mas_right).with.offset(10);
        make.width.equalTo(@100);
        make.height.equalTo(@15);
        make.top.equalTo(_title.mas_bottom).with.offset(10);
    }];
    // 评论
    [_replysimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_photo.mas_right).with.offset(10);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
        make.width.equalTo(@15);
        make.height.equalTo(@15);
    }];
    [_replys mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_photo.mas_right).with.offset(30);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
        make.width.equalTo(@50);
        make.height.equalTo(@15);
    }];
    // 查看
    [_viewimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_photo.mas_right).with.offset(85);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
        make.width.equalTo(@15);
        make.height.equalTo(@15);
    }];
    [_views mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_viewimg.mas_right).with.offset(5);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
        make.width.equalTo(@50);
        make.height.equalTo(@15);
    }];
}


- (void)setModel:(OMGHomeModel *)model
{
    _model = model;
    _title.text = _model.title;
    // 图片
    [_photo sd_setImageWithURL:[NSURL URLWithString:model.photo]placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    // 用户名
    _username.text = model.username;
    // 评论
    _replys.text = model.replys;
    // 查看
    _views.text = [model.views stringValue];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
